package com.kuang.springboot2board.config;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author Gerald
 * @date 2022/6/13-23:13
 */

//中文和英文之间互相转换
public class MyLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {

        String language=request.getParameter("l");
        Locale locale=Locale.getDefault();//如果没有就使用默认的
        if(!StringUtils.isEmpty(language)){
            String[] split=language.split("_");//en_US 得到这个数据
            locale=new Locale(split[0],split[1]);
        }
        return locale;//返回到首页
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
